package com.chai.config;

import org.springframework.web.context.WebApplicationContext;

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * 加载容器的配置类
 * */
public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    /**
     * post请求乱码的处理
     * filter过滤器
     * */
    @Override
    protected Filter[] getServletFilters() {
        //springweb中提高的过滤器


        CharacterEncodingFilter cef=new CharacterEncodingFilter();
        cef.setEncoding("UTF-8");
        return new Filter[]{cef};
    }
}


/*public class ServletConfig extends AbstractDispatcherServletInitializer {
    *//**
     * 加载SpringMVC的配置容器
     * *//*
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        //加载springmvc配置类
        AnnotationConfigWebApplicationContext act=new AnnotationConfigWebApplicationContext();
        act.register(SpringMvcConfig.class);
        return act;
    }
    *//**
     * 那些请求交给springmvc进行处理
     * *//*
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
    *//**
     * 加载spring的配置容器
     * *//*
    @Override
    protected WebApplicationContext createRootApplicationContext() {
        AnnotationConfigWebApplicationContext act=new AnnotationConfigWebApplicationContext();
        act.register(SpringConfig.class);
        return act;
    }

}*/
